package org.threadCase3;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class RunnableDemo implements Runnable{
    public static int count=1;
    private Lock lock=new ReentrantLock();
    @Override
    public void run() {
        while (true){
            lock.lock();
            try {
                if (count>100){
                    break;
                }else {
                    Thread.sleep(500);
                    if (count%2==1){
                        System.out.println(Thread.currentThread().getName()+"奇数:"+count);
                    }
                    count++;

                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } finally {
                lock.unlock();
            }
        }
    }
}
